package com.inspur.gs.sbssdl.sbwhgl.sbwhby.sbwhby.front.sbbyszlist_frm.voactions;
import com.inspur.edp.bff.api.manager.context.QueryContext;
import com.inspur.edp.bff.spi.action.query.BeforeQueryAction;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.condition.FilterCondition;

import java.util.ArrayList;

public class beforeQueryVOAction extends BeforeQueryAction {

	public beforeQueryVOAction(QueryContext context){
		super(context);
	}
	@Override
	public void execute() {
		String mainName = (String) this.getContext().getVariableData().getValue("mainName");
		String className = (String) this.getContext().getVariableData().getValue("className");
		String bydj = (String) this.getContext().getVariableData().getValue("bydj");

		//第一级：mainName
		//第二级：className==>mainName
		//第三级：className==>bydj==>mainName

		if (mainName != null && !mainName.isEmpty()){
			EntityFilter filter = getQueryContext().getFilter();
			if (className==null&&bydj==null){
				ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
						.andEqual("sbdl", mainName)
						.build());
				filter.addFilterConditions(filterList);
			}else if(className!=null&&bydj==null){
				ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
						.andEqual("sbxl", mainName)
						.andEqual("sbdl", className)
						.build());
				filter.addFilterConditions(filterList);
			}else if(className!=null&&bydj!=null){
				ArrayList<FilterCondition> filterList = new ArrayList<>(FilterCondition.builder()
						.andEqual("sbxl", bydj)
						.andEqual("sbdl", className)
						.andEqual("bydj", mainName)
						.build());
				filter.addFilterConditions(filterList);
			}
		}
	}
}
